<template>
  <div>
    <div style="display: flex;margin-bottom:10px;">
      <el-upload width="2000px" class="upload-demo" :action="action" :data='filedata' :on-success='uploadsuccess'
        :on-error='uploaderror' :on-progress='progressing' :headers="headers" :show-file-list='false'>
        <el-button size="small" type="primary">导入</el-button>
      </el-upload>
      <el-button type="primary" size="mini" @click="save()">保存</el-button>
    </div>
    <el-progress :percentage="schedule" v-if="showuploading==1"></el-progress>
    <el-descriptions class="right-condition-table" title="" :column="1" size="medium " border>
      <el-descriptions-item label="试卷名">{{exampaperinfo.testName}}</el-descriptions-item>
      <el-descriptions-item label="出卷人">{{exampaperinfo.testFounder}}</el-descriptions-item>
      <el-descriptions-item label="单选题数量">{{exampaperinfo.singleNum}}</el-descriptions-item>
      <el-descriptions-item label="单选题分值">{{exampaperinfo.singleScore}}</el-descriptions-item>
      <el-descriptions-item label="单选题总分">{{exampaperinfo.singleNum*exampaperinfo.singleScore}}</el-descriptions-item>
      <el-descriptions-item label="多选题数量">{{exampaperinfo.multipleNum}}</el-descriptions-item>
      <el-descriptions-item label="多选题分值">{{exampaperinfo.multipleScore}}</el-descriptions-item>
      <el-descriptions-item label="多选题总分">{{exampaperinfo.multipleNum*exampaperinfo.multipleScore}}
      </el-descriptions-item>
      <el-descriptions-item label="判断题数量">{{exampaperinfo.judgmentNum}}</el-descriptions-item>
      <el-descriptions-item label="判断题分值">{{exampaperinfo.judgmentScore}}</el-descriptions-item>
      <el-descriptions-item label="判断题总分">{{exampaperinfo.judgmentNum*exampaperinfo.judgmentScore}}
      </el-descriptions-item>
      <el-descriptions-item label="题目总数">
        {{exampaperinfo.singleNum*1 + exampaperinfo.multipleNum*1 + exampaperinfo.judgmentNum*1}}
      </el-descriptions-item>
      <el-descriptions-item label="试题总分">
        {{exampaperinfo.singleNum*exampaperinfo.singleScore+exampaperinfo.multipleNum*exampaperinfo.multipleScore+exampaperinfo.judgmentNum*exampaperinfo.judgmentScore}}
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
  import {base} from "../../../util/requests";
  export default {
    name: 'Examinfo',
    props: ['exampaperinfo'],
    data() {
      return {
        // testinfo: {},
        filedata: {
          'testUUId': this.$route.query.testUuid
        },
        action: base+'/questionInfo/uploadExcel',
        schedule: 0,
        showuploading: 0.,
        headers: {
          'token': localStorage.getItem('token')
        }
      }
    },
    mounted() {
      // this.testinfo = exampaperinfo
      // console.log('testuuid',this.$route.query.testUuid)
    },
    methods: {
      save() {
        this.$postRequest({
          url: '/answerInfo/saveAnswer',
          params:{
            'testUUId':this.filedata.testUUId
          }
        }).then(res=>{
          console.log(res)
          if(res.code==200){
            this.$message({
              type: 'success',
              message: '保存成功！'
            })
            this.$router.go(-1);
          }else{
            this.$message({
              type: 'info',
              message: '保存失败！'
            })
          }
        })

      },
      uploadsuccess(response, file, fileList) { //上传成功
        this.$message({
          type: 'success',
          message: '文件上传成功！'
        })
        this.$store.commit('changenewpage', 1)
        setTimeout(() => {
          this.showuploading = 0
        }, 2000)
      },
      uploaderror(err, file, fileList) { //上传失败
        this.$message({
          message: '文件上传失败',
          type: 'error'
        })
        setTimeout(() => {
          this.showuploading = 0
        }, 2000)
        // console.log(err)
      },
      progressing(event, file, filelist) {
        this.showuploading = 1
        this.schedule = event.percent
        // console.log('上传中',event.percent)
        // console.log('file',file)
        // console.log('filelist',filelist)
      }
    }
  }
</script>

<style>
  .right-condition-table {
    width: 100%;
    /* height: 6.25rem; */
  }

  .upload-demo {
    margin-left: 10%;
    margin-right: 20px;
  }
</style>
